var M17FrontendEditBackend = new Class({
    Implements: [Options, Events],
    options: {
    },
    initialize: function(options){
        this.setOptions(options);
        this.changeGui();
        this.getUri = new URI(location.href);
        this.save(this.getType());
    },
    save: function(type) {
        var _el = document.id(type) || false;
        
        if(_el) {
            var _typeSelect = _el.getElement('#ctrl_type'),
                _formUri = new URI(_el.get('action'));
            /* Remove the contao Event */
            _typeSelect.erase('onchange');
            
            _el.set('action', _formUri.setData('m17SaveTrigger', true));
            _el.set('action', _formUri.setData('m17FeEdit', true));
            
            _typeSelect.addEvent('change', function(e) {
                _el.set('action', _formUri.setData('m17SaveTrigger', false));
                Backend.autoSubmit('tl_content');
            }.bind(this));
            

            _el.addEvent('submit', function() {
                parent.document.id('mbOverlay').fade('out');
                parent.document.id('mbCenter').fade('out');
            }.bind(this));
        }
        if(location.href.contains('m17SaveTrigger=true')) {
            parent.location.href = parent.location.href;
        }
    },
    getType: function() {
        return this.getUri.getData('table');
    },
    changeGui: function() {
        document.id('left').setStyle('display', 'none');
        document.id('header').setStyle('display', 'none');
        document.id('footer').setStyle('display', 'none');
        document.id('container').setStyle('margin', '0');
        document.id('container').setStyle('width', 'auto');
        document.id('main').setStyle('margin', '0');
    }
});
if(location.href.contains('m17FeEdit=true')) {
    window.addEvent('domready', function() {
        var m17FeEdit = new M17FrontendEditBackend();
    });
}